
const express = require('express')
const cookieParser = require('cookie-parser')
const session = require('express-session')

const app = express()
app.use(cookieParser())
app.use(session({
    secret:'djkk',
    cookie:{
        expires:1000*60*2
    },
    resave:false,
    saveUninitialized:false

}))

app.get('/session',(req,res)=>{
    if(!req.session.name){
        req.session.name='王五'
    }
    res.send("设置session")
})

app.get('/count',(req,res)=>{
    if(!req.session.count){
        req.session.count=1
    }
    req.session.count++
    res.send("count:"+req.session.count)
})





// app.get('/',(req,res)=>{
//     res.send(req.cookies)
// })

// app.get('/add/cookie',(req,res)=>{
//     let {username,userage,userpwd} = req.query
//     res.cookie('username',username)
//     res.cookie('userage',userage)
//     res.cookie('userpwd',userpwd,{maxAge:1000*60*60*24*10,domain:'taobao.com'})
//     res.send('设置成功')
// })

// app.get('/clear/cookie',(req,res)=>{
//     res.clearCookie('username')
//     res.clearCookie('userage')
//     res.clearCookie('userpwd')
//     res.redirect('/')
// })

app.listen(3000,()=>{
    console.log(`服务已启动...`);
})